package com.example.knowledge.mvvm.fragment

import android.view.View
import com.alibaba.android.arouter.facade.annotation.Route
import com.example.knowledge.R
import com.example.knowledge.mvvm.activity.ReportActivity
import com.gsafety.libraryktx.base.BaseFragment
import com.gsafety.libraryktx.config.Constant
import com.gsafety.libraryktx.core.RouterConstants
import com.gsafety.libraryktx.manager.UserManager
import kotlinx.android.synthetic.main.know_fragment_layout.*

@Route(path = RouterConstants.KNOW_FRAGMENT)
class KnowFragment : BaseFragment(),View.OnClickListener {

    override fun initView(view: View?) {
        initcode()
    }

    override fun initData() {
        ll_yuebao.setOnClickListener(this)
        ll_jibao.setOnClickListener(this)
        ll_nianbao.setOnClickListener(this)
    }

    override fun getLayoutId(): Int {
        return R.layout.know_fragment_layout
    }



    private  fun initcode(){
        var codes= UserManager.getInstance().appModelCodes()
        codes?.also {
            //分析报告
            if(!it.contains(Constant.CODE_ANALYSIS_REPORT))  {
                label_analyse_report.visibility=View.GONE
            }
            //月报
            if(!it.contains(Constant.CODE_MONTH)){
                ll_yuebao.visibility=View.GONE
            }
            //季报
            if(!it.contains(Constant.CODE_QUARTERLY_REPORT)){
                ll_jibao.visibility=View.GONE
            }
            //年报
            if(!it.contains(Constant.CODE_YEAR_REPORT)){
                ll_nianbao.visibility=View.GONE
            }
            //辅助决策
            if(!it.contains(Constant.CODE_FUZHU_ANALYSIS)){
                label_assist_decision.visibility=View.GONE
            }
            //事件库
            if(!it.contains(Constant.CODE_SJ)){
                ll_event.visibility=View.GONE
            }
            //预案库
            if(!it.contains(Constant.CODE_YA)){
                ll_yuan.visibility=View.GONE
            }
            //案例库
            if(!it.contains(Constant.CODE_CASE)){
                ll_anli.visibility=View.GONE
            }
        }
    }

    override fun onClick(v: View) {
        when(v.id){
            R.id.ll_yuebao->{
             ReportActivity.startIntent(mContext!!,"月报",Constant.CODE_REPORT_MONTH)
            }
            R.id.ll_jibao->{
                ReportActivity.startIntent(mContext!!,"季报",Constant.CODE_REPORT_JI)
            }
            R.id.ll_nianbao->{
                ReportActivity.startIntent(mContext!!,"年报",Constant.CODE_REPORT_YEAR)
            }
        }
    }


}